package com.aifund.admin.service.impl;

import com.aifund.admin.entity.form.config.ConfigPageForm;
import com.aifund.admin.entity.vo.PageResult;
import com.aifund.admin.service.SystemConfigAdminService;
import com.aifund.common.dao.SystemConfigDao;
import com.aifund.common.entity.SystemConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class SystemConfigServiceAdminImpl implements SystemConfigAdminService {

    @Autowired
    SystemConfigDao systemConfigDao;

    @Override
    public PageResult<SystemConfig>  page(ConfigPageForm form) {
        Sort sort = Sort.by(Sort.Direction.ASC,"id");
        Pageable pageable = PageRequest.of(form.getPageIndex()-1,form.getPageSize(),sort);
        Page<SystemConfig> systemConfigsPage = systemConfigDao.findAll(pageable);
        PageResult<SystemConfig> pageResult = new PageResult<>();
        return pageResult.success(systemConfigsPage,form.getPageIndex()-1,form.getPageSize());
    }
}
